/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package blms.domain;

import static blms.util.ValidatorUtil.isBlankOrNull;

import java.io.File;

import blms.exception.ValidationException;
import blms.util.BLMSMessages;

/**
 * Aggregates information about a billiard player in the BLMS system.
 * 
 * @author João Arthur
 * @author Jonhnny Weslley
 * @author Thiago Emmanuel
 * @version 1.00, 21/04/2008
 * @since 1.0
 */
public class User extends Entity {

	private static final long serialVersionUID = 2810537784994672578L;

	private String email;
	private String firstName;
	private String lastName;
	private String homePhone;
	private String workPhone;
	private String cellPhone;
	private File picture;

	public User() {
		// Default constructor
	}

	public User(final String firstName, final String lastName,
			final String homePhone, final String workPhone,
			final String cellPhone, final String email, final File picture) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.homePhone = homePhone;
		this.workPhone = workPhone;
		this.cellPhone = cellPhone;
		this.email = email;
		this.picture = picture;
	}

	public void validate() throws ValidationException {
		if (isBlankOrNull(firstName) || isBlankOrNull(lastName)
				|| isBlankOrNull(email)) {

			String message = (isBlankOrNull(firstName)) ? "first name" : "";
			if (isBlankOrNull(lastName)) {
				message = (message.equals("")) ? message + "last name"
						: message + ", " + "last name";
			}
			if (isBlankOrNull(email)) {
				message = (message.equals("")) ? message + "email" : message
						+ ", " + "email";
			}
			throw new ValidationException(BLMSMessages.REQUIRED_DATA_MESSAGE
					+ message);
		}

		if (isBlankOrNull(homePhone) && isBlankOrNull(workPhone)
				&& isBlankOrNull(cellPhone)) {
			throw new ValidationException(
					BLMSMessages.NEED_AT_LEAST_ONE_PHONE_MESSAGE);
		}
	}

	/**
	 * Returns the first name and the last name of this User.
	 * 
	 * @return the first name and the last name of this User.
	 */
	public String getName() {
		return firstName + " " + lastName;
	}
	
	/**
	 * Returns the email of this User.
	 * 
	 * @return the email of this User.
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Sets the email of this User.
	 * 
	 * @param email
	 *            the email of the user.
	 */
	public void setEmail(final String email) {
		this.email = email;
	}

	/**
	 * Returns the first name of this User.
	 * 
	 * @return the first name of this User.
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Sets the first name of this User.
	 * 
	 * @param firstName
	 *            the first name of this User.
	 */
	public void setFirstName(final String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Returns the last name of this User.
	 * 
	 * @return the last name of this User.
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Sets the last name of this User.
	 * 
	 * @param lastName
	 *            the last name of this User.
	 */
	public void setLastName(final String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Returns the home phone of this User.
	 * 
	 * @return the home phone of this User.
	 */
	public String getHomePhone() {
		return homePhone;
	}

	/**
	 * Sets the home phone of this User.
	 * 
	 * @param homePhone
	 *            the home phone of this User.
	 */
	public void setHomePhone(final String homePhone) {
		this.homePhone = homePhone;
	}

	/**
	 * Returns the work phone of this User.
	 * 
	 * @return the work phone of this User.
	 */
	public String getWorkPhone() {
		return workPhone;
	}

	/**
	 * Sets the work phone of this User.
	 * 
	 * @param workPhone
	 *            the work phone of this User.
	 */
	public void setWorkPhone(final String workPhone) {
		this.workPhone = workPhone;
	}

	/**
	 * Returns the cell phone of this User.
	 * 
	 * @return the cell phone of this User.
	 */
	public String getCellPhone() {
		return cellPhone;
	}

	/**
	 * Sets the cell phone of this User.
	 * 
	 * @param cellPhone
	 *            the cell phone of this User.
	 */
	public void setCellPhone(final String cellPhone) {
		this.cellPhone = cellPhone;
	}

	/**
	 * Returns the picture of this User.
	 * 
	 * @return the pictureof this User.
	 */
	public File getPicture() {
		return picture;
	}

	/**
	 * Sets the picture of this User.
	 * 
	 * @param picture
	 *            the picture of this User.
	 */
	public void setPicture(final File picture) {
		this.picture = picture;
	}
}